﻿using PRO.Public;
using PRO.User;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PRO.Common;
using PRO.Product;
using PRO.Config;

namespace web.Member.favorite
{
    public partial class view : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "我的愿望盒-" + BaseConfigs.Title;
            if (UserInfo.ID == 0)
                Response.Redirect("/login?url=" + Request.RawUrl.UrlEncode());
            else
                Bind();
        }
        private void Bind()
        {
            int counts = 0;
            int pages = 0;
            this.Pager1.PageSize = 12;
            DataTable dt = PublicLib.CutPage("Pro_Favorite left join Pro_Product on Pro_Product.id=Pro_Favorite.pid", "Pro_Favorite.id", "Pro_Favorite.id desc", this.Pager1.PageIndex, this.Pager1.PageSize, "Pro_Favorite.id,Pro_Favorite.pid,Pro_Product.title,Pro_Product.show", "Pro_Favorite.userid=" + UserInfo.ID, "", out pages, out counts);
            this.Pager1.RecordCount = counts;
            this.Repeater1.DataSource = dt;
            this.Repeater1.DataBind();
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = e.CommandArgument.ToInt(0);
            if (id > 0)
            {
                switch (e.CommandName)
                { 
                    case "del":
                        FavoriteLib.DelToFavorite(id, UserInfo.ID);
                        break;
                }
                
            }
            Bind();
        }

        protected void Pager1_PageIndexChanging(object sender, PRO.Controls.Pager.NumericaArgs e)
        {
            this.Pager1.PageIndex = e.NewPageIndex;
            Bind();
        }
    }
}